<template>
  <a-drawer
    :title="formInfo.id==undefined?'新增':'修改'"
    :maskClosable="true"
    :width="drawerWidth"
    placement="right"
    :closable="true"
    @close="handleCancel"
    :destroyOnClose="true"
    :visible="visible"
    style="height: calc(100% - 55px);overflow: auto;padding-bottom: 53px;">
    <a-spin :spinning="confirmLoading">
      <a-form-model
        ref="ruleForm"
        :model="formInfo"
        :label-col="$global.labelCol"
        :wrapper-col="$global.wrapperCol"
      >
            <a-row>
              <a-col :span="12">
            <a-form-model-item label="业务流水号" prop="busNo" :rules="$valid.required" :maxLength="50">
              <a-input v-model="formInfo.busNo" placeholder="请输入业务流水号"/>
            </a-form-model-item>
          </a-col>
                  <a-col :span="12">
            <a-form-model-item label="业务标识" prop="busType" :rules="$valid.required" :maxLength="50">
              <a-input v-model="formInfo.busType" placeholder="请输入业务标识"/>
            </a-form-model-item>
          </a-col>
            </a-row>
                <a-row>
              <a-col :span="12">
            <a-form-model-item label="患者姓名" prop="payer" :rules="$valid.required" :maxLength="50">
              <a-input v-model="formInfo.payer" placeholder="请输入患者姓名"/>
            </a-form-model-item>
          </a-col>
                  <a-col :span="12">
            <a-form-model-item label="业务流水号" prop="busDateTime" :rules="$valid.required" :maxLength="50">
              <a-input v-model="formInfo.busDateTime" placeholder="请输入业务流水号"/>
            </a-form-model-item>
          </a-col>
            </a-row>
                <a-row>
              <a-col :span="12">
            <a-form-model-item label="入参" prop="invoicetext" :rules="$valid.required" :maxLength="50">
              <a-input v-model="formInfo.invoicetext" placeholder="请输入入参"/>
            </a-form-model-item>
          </a-col>
                  <a-col :span="12">
            <a-form-model-item label="是否开具" prop="fpFlag">
              <a-select v-model="formInfo.fpFlag" placeholder="请选择是否开具">
                <a-select-option v-for="(item) in this.$sysDictOptions('fpFlag')" :key="item.k" :value="parseInt(item.k)">
                  {{ item.v }}
                </a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
            </a-row>
                <a-row>
              <a-col :span="12">
            <a-form-model-item label="关联id" prop="recordid" :rules="$valid.required" :maxLength="50">
              <a-input v-model="formInfo.recordid" placeholder="请输入关联id"/>
            </a-form-model-item>
          </a-col>
                  <a-col :span="12">
            <a-form-model-item label="开票点编码" prop="placeCode" :rules="$valid.required" :maxLength="50">
              <a-input v-model="formInfo.placeCode" placeholder="请输入开票点编码"/>
            </a-form-model-item>
          </a-col>
            </a-row>
                <a-row>
              <a-col :span="12">
            <a-form-model-item label="返回结果标识" prop="result" :rules="$valid.required" :maxLength="50">
              <a-input v-model="formInfo.result" placeholder="请输入返回结果标识"/>
            </a-form-model-item>
          </a-col>
                  <a-col :span="12">
            <a-form-model-item label="返回结果内容" prop="message" :rules="$valid.required" :maxLength="50">
              <a-input v-model="formInfo.message" placeholder="请输入返回结果内容"/>
            </a-form-model-item>
          </a-col>
            </a-row>
                <a-row>
              <a-col :span="12">
            <a-form-model-item label="电子票据代码" prop="billBatchCode" :rules="$valid.required" :maxLength="50">
              <a-input v-model="formInfo.billBatchCode" placeholder="请输入电子票据代码"/>
            </a-form-model-item>
          </a-col>
                  <a-col :span="12">
            <a-form-model-item label="电子票据号码" prop="billNo" :rules="$valid.required" :maxLength="50">
              <a-input v-model="formInfo.billNo" placeholder="请输入电子票据号码"/>
            </a-form-model-item>
          </a-col>
            </a-row>
                <a-row>
              <a-col :span="12">
            <a-form-model-item label="电子校验码" prop="random" :rules="$valid.required" :maxLength="50">
              <a-input v-model="formInfo.random" placeholder="请输入电子校验码"/>
            </a-form-model-item>
          </a-col>
                  <a-col :span="12">
            <a-form-model-item label="电子票据生成时间" prop="createTimep" :rules="$valid.required" :maxLength="50">
              <a-input v-model="formInfo.createTimep" placeholder="请输入电子票据生成时间"/>
            </a-form-model-item>
          </a-col>
            </a-row>
                <a-row>
              <a-col :span="12">
            <a-form-model-item label="是否红冲" prop="billFlag">
              <a-select v-model="formInfo.billFlag" placeholder="请选择是否红冲">
                <a-select-option v-for="(item) in this.$sysDictOptions('billFlag')" :key="item.k" :value="parseInt(item.k)">
                  {{ item.v }}
                </a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
                  <a-col :span="12">
            <a-form-model-item label="冲红原因" prop="reason" :rules="$valid.required" :maxLength="50">
              <a-input v-model="formInfo.reason" placeholder="请输入冲红原因"/>
            </a-form-model-item>
          </a-col>
            </a-row>
                <a-row>
              <a-col :span="12">
            <a-form-model-item label="冲红经办人" prop="operator" :rules="$valid.required" :maxLength="50">
              <a-input v-model="formInfo.operator" placeholder="请输入冲红经办人"/>
            </a-form-model-item>
          </a-col>
                </a-row>
          </a-form-model>
    </a-spin>
    <div class="drawer-bootom-button">
      <a-popconfirm title="确定放弃编辑？" @confirm="handleCancel" okText="确定" cancelText="取消">
        <a-button style="margin-right: .8rem">取消</a-button>
      </a-popconfirm>
      <a-button @click="handleSubmit" type="primary" :loading="confirmLoading">提交</a-button>
    </div>
  </a-drawer>
</template>

<script>
  import { getAction, postAction } from '@/api/manage'
  export default {
    name: 'UserWaterInvoiceEdit',
    components: {
    },
    data () {
      return {
        visible: false,
        confirmLoading: false,
        formInfo: {
          createTime: undefined,
          busNo: undefined,
          busType: undefined,
          payer: undefined,
          busDateTime: undefined,
          invoicetext: undefined,
          fpFlag: undefined,
          recordid: undefined,
          placeCode: undefined,
          result: undefined,
          message: undefined,
          billBatchCode: undefined,
          billNo: undefined,
          random: undefined,
          createTimep: undefined,
          billFlag: undefined,
          reason: undefined,
          operator: undefined,
          wx: ''
        },
        drawerWidth: 800,
        url: {
          saveInfo: '/system/userWaterInvoice/save',
          getInfo: '/system/userWaterInvoice/info'
        }
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit()
      },
      edit (record) {
        this.$objToOverride(this.formInfo, record)
        if (this.formInfo.id) {
          getAction(this.url.getInfo, { 'id': record.id }).then(res => {
            this.$nextTick(() => {
              this.formInfo = res.result.data
            })
          })
        }
        this.visible = true
      },
      // 确定
      handleSubmit () {
        // 触发表单验证
        this.confirmLoading = true
        this.$refs.ruleForm.validate(valid => {
          console.log(valid)
          if (valid) {
            postAction(this.url.saveInfo, this.formInfo).then(res => {
              this.$message.success(res.content)
              this.$emit('ok', this.formInfo)
              this.close()
            }).finally(() => {
              this.confirmLoading = false
            })
          } else {
            this.confirmLoading = false
          }
        })
      },
      // 关闭
      handleCancel () {
        this.close()
      },
      close () {
        this.$refs.ruleForm.resetFields()
        this.$objToReset(this.formInfo)
        this.$emit('close')
        this.visible = false
      },
      editorOk (val) {
        this.formInfo.content = val
      }
    }
  }
</script>
